package engine.ui 
{
	import engine.data.ModelLocator;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.ui.lite.BaseUI;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import newx.com.control.button.NxButton;
	import newx.com.control.text.NxLabel;
	import newx.com.control.text.NxText;
	import newx.com.control.window.NxWindowEvent;
	
	/**
	 * ...
	 * @author ...gyq
	 */
	public class GoldLoseUI extends BaseUI 
	{
		private static var _self:GoldLoseUI;
		private static var _model			:ModelLocator;
		private static  const NO_ENOUTH_GOLD:int = 2; //金币不足
		public static  const GET_NEW_EQUIP:int = 0;	//获得新装备
		private static  const DEAD_IN_FB:int = 1;		//副本中死亡
		public var btn_getGold:NxButton;
		public var btn_activity:NxButton;
		public var txt_info:NxText;
		public var checkbox:MovieClip;
		public var lab_notice:NxLabel;
		public var _isopen:int = 1;
		public function GoldLoseUI() 
		{
			
		}
		
		public static function getInstance():GoldLoseUI
		{
			if(_self == null)
			{
				_self = new GoldLoseUI();
			}
			return _self;
		}
		
		override public function Init():void
		{
			checkbox.buttonMode = true;
			lab_notice.buttonMode = true;
			_model = ModelLocator.getInstance();
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_PROMPT), onShow);
		}
		
		
		private function oncheckboxHandle(e:MouseEvent):void
		{
			if (_isopen == 1)
			{
				checkbox.gotoAndStop(2);
				_isopen = 2;
			}else
			if (_isopen == 2)
			{
				checkbox.gotoAndStop(1);
				_isopen = 1;
			}
		}
		private function onShow(e:CustomMsgEvent):void
		{
			if (e.pList[0] == NO_ENOUTH_GOLD)
			{
				if (_isopen == 1)
				{
					show();
				}
			}else if (e.pList[0] == GET_NEW_EQUIP)
			{
//				if (EquipUpdataUI.getInstance()._isopen == 1)
//				{
//					EquipUpdataUI.getInstance().onShow(e.pList[1]);
//				}
				
				
			}else if (e.pList[0] == DEAD_IN_FB)
			{
//				if (LoseNoticeUI.getInstance()._isopen == 1)
//				{
//					LoseNoticeUI.getInstance().show();
//				}
			}
		}
		private function onClickClose(e:NxWindowEvent):void
		{
			hide();
		}
		
		private function onGoldHandle(e:MouseEvent):void
		{
			MagicChangeToGoldUI.getInstance().showByType();
		}
		
		private function onActivityHandle(e:MouseEvent):void
		{
			ActivityExplainNextUI.getInstance().show();
			ActivityExplainNextUI.getInstance().showContent(6, 1);
		}
		/**
		 *添加监听 
		 * 
		 */
		private function addListenter():void
		{
			checkbox.addEventListener(MouseEvent.CLICK, oncheckboxHandle);
			lab_notice.addEventListener(MouseEvent.CLICK, oncheckboxHandle);
			windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			btn_getGold.addEventListener(MouseEvent.CLICK,onGoldHandle);
			btn_activity.addEventListener(MouseEvent.CLICK,onActivityHandle);
		}
		
		
		/**
		 *移除监听 
		 * 
		 */
		private function removeListenter():void
		{
			checkbox.removeEventListener(MouseEvent.CLICK, oncheckboxHandle);
			lab_notice.removeEventListener(MouseEvent.CLICK, oncheckboxHandle);
			windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE, onClickClose);
			btn_getGold.removeEventListener(MouseEvent.CLICK,onGoldHandle);
			btn_activity.removeEventListener(MouseEvent.CLICK,onActivityHandle);
		}
		
		override protected function BeforeShow():void
		{
			checkbox.gotoAndStop(_isopen);
			addListenter();
		}
		
		override protected function AfterHide():void
		{
			removeListenter();
		}
		
	}

}